Arduino – CLCD with I2C – Screensaver
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
#include <Wire.h> #include <LiquidCrystal_I2C.h> LiquidCrystal_I2C lcd(0x27,16,2); // or 0x3F #define timeBacklight 5000 #define timeDisplay 8000 int button1=4; int button2=5; unsigned long cnt=0; boolean stateButton=0; void setup() { pinMode(button1, INPUT); pinMode(button2, INPUT); lcd.init(); delay(1000); lcd.backlight(); lcd.setCursor(0,0); lcd.print("Hello World!"); cnt=millis(); } void loop() { lcd.setCursor(0,1); lcd.print(millis()); if (digitalRead(button1) || digitalRead(button2)) { stateButton=true; } if (stateButton) { cnt=millis(); stateButton=false; lcd.display(); lcd.backlight(); } if (millis()-cnt > timeDisplay) { lcd.noDisplay(); } else if (millis()-cnt > timeBacklight) { lcd.noBacklight(); } } |